﻿using RPAVIEW.util;
using RPAVIEW.views.controlLibrary;
using SUNRPA.CONTROLS.IMPL.util;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;

namespace RPAVIEW.views.EditPage.flows.StartExcelN {
    /// <summary>
    /// Input.xaml 的交互逻辑
    /// </summary>
    public partial class Input:BaseParamViewAction{
        public Input() {
            InitializeComponent();
        }

        public override void UpdateSource() {
            this.startWay.GetBindingExpression(System.Windows.Controls.ComboBox.SelectedIndexProperty).UpdateSource();
            this.excelPath.GetBindingExpression(SelVarTextBox.text).UpdateSource();
            this.driver.GetBindingExpression(System.Windows.Controls.ComboBox.SelectedIndexProperty).UpdateSource();
            this.isVisable.GetBindingExpression(System.Windows.Controls.CheckBox.IsCheckedProperty).UpdateSource();
        }

        private void StartWayChanged(object sender, SelectionChangedEventArgs e) {
            int selectWay = this.startWay.SelectedIndex;
            FlowEditWindow window = WindowUtil.GetWindow<FlowEditWindow>();
            Advance advacePage = window.Advance.advanceContent.Children[0] as Advance;
            if(selectWay == 0) {
                this.selectBtn.Content = "选择文件";
                advacePage.openCodeLabel.Height = GridLength.Auto;
            } else { 
                this.selectBtn.Content = "新建路径";
                advacePage.openCodeLabel.Height = new GridLength(0);
            }
        }

        private void SelectFileOrDir(object sender, RoutedEventArgs e) {
            int selectWay = this.startWay.SelectedIndex;
            if(selectWay == 0) { 
                //选择文件
                string path = string.Empty;
                Microsoft.Win32.OpenFileDialog openFileDlg = FileUtil.OpenFileSelectDialog(".xls;.xlsx", "Excel/Wps (*.xls,*.xlsx)|*.xls;*.xlsx", path);
                // 调用ShowDialog方法显示对话框
                openFileDlg.ShowDialog();
                path = openFileDlg.FileName;
                this.excelPath.Text = path;
            } else { 
                SaveFileDialog saveDialog =  FileUtil.OpenSaveFileDialog(".xls;.xlsx|*.xls;*.xlsx");
                saveDialog.FileName = "WorkBook.xlsx";
                saveDialog.ShowDialog();
                this.excelPath.Text = saveDialog.FileName;
            }
        }
    }
}
